package com.tx.admin.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang3.StringUtils;

import com.tx.admin.util.common.UUIDUtils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@MappedSuperclass
@Data
public abstract class SuperEntity {

	@Id
	@ApiModelProperty("编号")
	private String id;
	

	@Temporal(TemporalType.TIMESTAMP)
	@ApiModelProperty("更新时间")
	private Date uptTime;
	
	@Temporal(TemporalType.TIMESTAMP)
	@ApiModelProperty("创建时间")
    private Date crtTime;



	@Override
	public boolean equals(Object obj) {
		
		if(obj instanceof SuperEntity) {

			SuperEntity other = (SuperEntity) obj;
			if (id == null) {
				return false;
			} else if (id.equals(other.id)) {
				return true;
			}else {
				return true;
			}
	
		}

		return super.equals(obj);
	}

	@Override
	public int hashCode() {
		return id.hashCode();
	}
	
	public boolean init() {
		if(StringUtils.isBlank(id)) {
			this.id = UUIDUtils.generateShortUuid();
		}
		if(this.crtTime == null) {
			this.crtTime = new Date();
		}
		this.uptTime = new Date();
		return true;
	}
	
	
}
